from email import header

import requests


class IhrmEmpApi(object):
    @classmethod
    def add_emp(cls,header,req_data):
        resp = requests.post(url="http://ihrm-test.itheima.net/api/sys/user",
        headers = header,json=req_data)
        return resp

    @classmethod
    def query_emp(self,emp_id,header):
        resp = requests.get(url="http://ihrm-test.itheima.net/api/sys/user"+emp_id,
        headers = header )
        return resp

    @classmethod
    def modify_emp(self, emp_id, header,req_data):
        resp = requests.put(url="http://ihrm-test.itheima.net/api/sys/user" + emp_id,
                            headers=header,json=req_data)
        return resp

    @classmethod
    def delete_emp(self, emp_id, header):
        resp = requests.delete(url="http://ihrm-test.itheima.net/api/sys/user" + emp_id,
                            headers=header)


if __name__ == '__main__':
    req_header ={"Authorization":"123456"}
    json ={
        "username":"",
        "password":"",
        "workNumber":""
    }
    modify_data = {"username":"放大镜"}
    response = IhrmEmpApi.add_emp(req_header,json)
    response1 = IhrmEmpApi.query_emp("1234567",req_header)
    response2 = IhrmEmpApi.modify_emp("1234567",req_header,modify_data)
    response3 = IhrmEmpApi.delete_emp("1234567",req_header)
    print("添加员工结果：",response.json())